home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
jwpsrc.zip
/
PRINT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-31
|
51KB
|
1,510 lines
/* Copyright (C) Stephen Chung, 1991-1993. All rights reserved. */
#include "jwp.h"
#include <math.h>
MEASUREINFO Measurements[] = {
{ "inches", "\"", 2, 1.00 },
{ "centimeters", " cm", 1, 2.536 },
{ "millimeters", " mm", 0, 25.36 },
{ "points", " pts", 1, 72.00 },
{ "pixels", " dots", 0, 0.00 },
{ NULL, NULL, 0, 0.00 }
};
static int PrintFrom, PrintTo;
static HWND printdlghwnd;
static BOOL UserAbort, PrintError;
#define ESCAPECHAR '&'
static struct {
char escape;
int summary;
} HeaderStrings[] = {
{ 'L', 0 },
{ 'S', 1 },
{ 'A', 2 },
{ 'K', 3 },
{ 'C', 4 },
{ 'T', -1 },
{ 'D', -2 },
{ 'P', -3 },
{ 'F', -4 },
{ '\0', 0 }
};
MEASUREMENT FindMeasurement (char *name, MEASUREMENT measure)
{
int i;
if (measure >= 0) {
strcpy(name, Measurements[measure].name);
return (measure);
}
for (i = 0; Measurements[i].name != NULL; i++) {
if (!stricmp(name, Measurements[i].name)) return ((MEASUREMENT) i);
}
return (-1);
}
HDC GetPrinterDC (BOOL IcOnly, char *name)
{
char buffer[MAXLINELEN];
char *device, *driver, *output;
/* Opens the printer device */
GetProfileString ("windows", "device", ",,,", buffer, MAXLINELEN);
if ((device = strtok(buffer, ",")) &&
(driver = strtok(NULL, ", ")) &&
(output = strtok(NULL, ", "))) {
if (name != NULL) sprintf(name, "%s on %s", device, output);
if (IcOnly) {
return (CreateIC(driver, device, output, NULL));
} else {
return (CreateDC(driver, device, output, NULL));
}
}
if (name != NULL) strcpy(name, "(None)");
return (NULL);
}
BOOL SetupPrinter (BOOL ReloadDriver)
{
HDC hdc;
POINT printdots;
double temp;
double nr_points[2], dpp[2];
char buffer[MAXLINELEN];
if (ReloadDriver) {
hdc = GetPrinterDC(TRUE, buffer);
if (hdc == NULL) {
ErrorMessage(global.hwnd, "There are no printer currently connected.\n\n");
hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
global.printer = "DISPLAY";
} else if (!(GetDeviceCaps(hdc, RASTERCAPS) & RC_BITBLT)) {
ErrorMessage(global.hwnd, "The current printer is incapable of printing bitmaps.\n\n"
"You will not be able to print.");
DeleteDC(hdc);
hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
global.printer = "DISPLAY";
} else {
global.printer = DupString(buffer);
}
global.resolution.x = GetDeviceCaps(hdc, LOGPIXELSX);
global.resolution.y = GetDeviceCaps(hdc, LOGPIXELSY);
global.printable.x = GetDeviceCaps(hdc, HORZRES);
global.printable.y = GetDeviceCaps(hdc, VERTRES);
Measurements[M_PIXELS].conversion = global.resolution.y;
global.paper[0] = (double) GetDeviceCaps(hdc, HORZSIZE) / Measurements[M_MM].conversion;
global.paper[1] = (double) GetDeviceCaps(hdc, VERTSIZE) / Measurements[M_MM].conversion;
}
dpp[0] = (double) global.resolution.x / 72.0;
dpp[1] = (double) global.resolution.y / 72.0;
/* We compensate for the printer's aspect ratio. If necessary, */
/* stretching or compressing the horizontal axis. */
printdots.y = PRINTFONT->height * global.printscale;
temp = (double) PRINTFONT->width * (double) global.printscale;
temp = temp * (double) global.resolution.x / (double) global.resolution.y;
printdots.x = temp;
/* This is the number of points per printing font */
nr_points[0] = (double) printdots.x / dpp[0];
nr_points[1] = (double) printdots.y / dpp[1];
global.dispscale = (double) BASEFONT->height / (double) PRINTFONT->height;
if (ReloadDriver) DeleteDC(hdc);
return (TRUE);
}
void InitPrinting (void)
{
SetupPrinter(TRUE);
}
void ChangePrinterOrFonts (void)
{
FILEOPTIONS *f;
HCURSOR hcursor;
HFONT hfont;
HDC hdc;
HWND FocusHwnd;
hcursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
ShowCursor(TRUE);
FocusHwnd = SetFocus(NULL);
SetupPrinter(TRUE);
hdc = GetPrinterDC(TRUE, NULL);
if (hdc == NULL) hdc = CreateIC("DISPLAY", NULL, NULL, NULL);
hfont = SelectAsciiFont(hdc, DefAsciiFont.facename, DefAsciiFont.size, NULL);
if (DefAsciiFont.hfont != NULL) DeleteObject(DefAsciiFont.hfont);
DefAsciiFont.hfont =
FindMatchingScreenFont(hfont, global.dispscale / global.printscale,
&(DefAsciiFont.textmetric));
DeleteObject(hfont);
DeleteDC(hdc);
FontCharWidth (0, -1); /* Reload width tables */
global.leading = (int) ((double) PRINTFONT->leading * global.dispscale);
if (global.leading % 2 != 0) global.leading++;
global.spacing = (int) ((double) PRINTFONT->spacing * global.dispscale);
if (global.spacing % 2 != 0) global.spacing++;
for (f = fileoptions; f != NULL; f = f->next) {
f->leading = global.leading;
f->spacing = global.spacing;
f->basefont = BASEFONT;
f->linelen = CalcLineLength(f);
ReformatFile(f);
if (!FindCaret(f, TRUE)) MoveIntoWindow(f);
InvalidateRect(f->hwnd, NULL, TRUE);
if(RULER(f).hwnd != NULL) InvalidateRect(RULER(f).hwnd, NULL, TRUE);
}
ShowCursor(FALSE);
SetCursor(hcursor);
if (FocusHwnd != NULL) SetFocus(FocusHwnd);
}
static void FormatTimeDate (char *timep, char *datep)
{
time_t t;
struct tm *tmp;
static int idate, itime;
static char sdate[3], stime[3], sam[6], spm[6];
static BOOL Filled = FALSE;
if (!Filled || (timep == NULL && datep == NULL)) {
idate = GetProfileInt("intl", "iDate", 0);
itime = GetProfileInt("intl", "iTime", 0);
GetProfileString("intl", "sDate", "/", sdate, 2);
GetProfileString("intl", "sTime", ":", stime, 2);
GetProfileString("intl", "s1159", "AM", sam, 5);
GetProfileString("intl", "s2359", "PM", spm, 5);
Filled = TRUE;
}
time(&t);
tmp = localtime(&t);
if (datep != NULL) {
sprintf(datep, "%d%s%02d%s%02d",
idate == 1 ? tmp->tm_mday : idate == 2 ? (tmp->tm_year % 100) : (tmp->tm_mon + 1), sdate,
idate == 1 ? (tmp->tm_mon + 1) : idate == 2 ? (tmp->tm_mon + 1) : tmp->tm_mday, sdate,
idate == 1 ? (tmp->tm_year % 100) : idate == 2 ? tmp->tm_mday : (tmp->tm_year % 100));
}
if (timep != NULL) {
if (itime == 1) {
sprintf(timep, "%02d%s%02d", tmp->tm_hour, stime, tmp->tm_min);
} else {
sprintf(timep, "%d%s%02d %s",
(tmp->tm_hour % 12) ? (tmp->tm_hour % 12) : 12, stime,
tmp->tm_min, (tmp->tm_hour / 12) ? spm : sam);
}
}
}
static void BuildHeaderString (FILEOPTIONS *f, KANJI far *kp, int PageNum, KANJI far *out)
{
int i, j, k;
char cch;
KANJI kch;
KANJI far *kp1;
j = 0;
for (i = 0; kp[i]; i++) {
kch = kp[i];
if (ISKANJI(kch)) cch = LOBYTE(TranslateJAscii(kch, TRUE));
else cch = LOBYTE(kch);
if ('a' <= cch && cch <= 'z') cch -= 32;
if (cch == ESCAPECHAR) {
i++;
if (ISKANJI(kp[i])) cch = LOBYTE(TranslateJAscii(kp[i], TRUE));
else cch = LOBYTE(kp[i]);
if ('a' <= cch && cch <= 'z') cch -= 32;
for (k = 0; HeaderStrings[k].escape; k++) {
if (HeaderStrings[k].escape == cch) break;
}
if (!HeaderStrings[k].escape) {
out[j++] = kch; out[j++] = kp[i]; break;
} else if (HeaderStrings[k].summary >= 0) {
kp1 = f->summary[HeaderStrings[k].summary];
if (kp1 != NULL) for (k = 0; kp1[k]; k++) out[j++] = kp1[k];
} else {
char buffer[50];
switch (HeaderStrings[k].summary) {
case -1: /* Time */